package com.taiyo.modules.api.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.taiyo.modules.api.entity.TProductEntity;
import com.taiyo.modules.api.service.TProductService;
import com.taiyo.common.utils.PageUtils;
import com.taiyo.common.utils.Query;
import com.taiyo.common.utils.R;




/**
 * 商品
 * 
 * @author zkcn
 * @email youeremail@163.com
 * @date 2018-01-16 11:33:44
 */
@RestController
@RequestMapping("/api/tproduct")
public class TProductController {
	@Autowired
	private TProductService tProductService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("api:tproduct:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<TProductEntity> tProductList = tProductService.queryList(query);
		int total = tProductService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(tProductList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("api:tproduct:info")
	public R info(@PathVariable("id") Long id){
		TProductEntity tProduct = tProductService.queryObject(id);
		
		return R.ok().put("tProduct", tProduct);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("api:tproduct:save")
	public R save(@RequestBody TProductEntity tProduct){
		tProductService.save(tProduct);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("api:tproduct:update")
	public R update(@RequestBody TProductEntity tProduct){
		tProductService.update(tProduct);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("api:tproduct:delete")
	public R delete(@RequestBody Long[] ids){
		tProductService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
